import turtle
turtle.setup()#建立一个窗口
turtle.bgcolor("black")
turtle.pensize()
f = 20
y_or_n = turtle.textinput('Input Please',"是否退出程序（输入y/n）：")
while y_or_n != 'y' :
    try:
        input_str=turtle.textinput('请输入信息，并以空格分开', "身高(米) 体重(公斤) 年龄 性别[男or女]:")
        str_list = input_str.split(' ')#注意打个空格
        height= float(str_list[0])
        weight= float(str_list[1])
        age= int(str_list[2])
        gender = str_list[3]
        def isBMR(a,b,c):
            if gender == "男":
                BMR = (13.7 * a) + (5.0 * b) - (6.8 * c) + 66
                print("BMR 数值为：{:.2f}".format(BMR))
            elif gender == "女":
                BMR = (9.6 * a) + (1.8 * b) - (4.7 * c) + 655
                print("BMR 数值为：{:.2f}".format(BMR))
            else:
                print("暂不支持此性别！")
            return BMR
        def isBMI(a,b):
            bmi = a / pow(b, 2)
            print("BMI数值为：{}".format(bmi))
            who, nat = "", ""
            if bmi< 18.5:
                who, nat = "偏瘦", "偏瘦"
            elif 18.5 <= bmi < 24:
                who, nat = "正常", "正常"
            elif 24 <= bmi < 25:
                who, nat = "正常", "偏胖"
            elif 25 <= bmi < 28:
                who, nat = "偏胖", "偏胖"
            elif 28 <=bmi < 30:
                who, nat = "偏胖", "肥胖"
            else:
                who, nat = "肥胖", "肥胖"
            print("BMI 指标为:国际'{0}', 国内'{1}'".format(who, nat))
            return bmi,who,nat
        isBMI(weight,height)
        isBMR(weight,height,age)
        g=f-20
        turtle.penup()
        turtle.pencolor('blue')
        turtle.goto(-225,g)
        turtle.pendown()
        turtle.write("BMI 指标:数值,国际,国内分别为{}".format(isBMI(weight,height)), font=("Arial", 16, "normal"))
        g=g-20
        turtle.penup()
        turtle.pencolor('blue')
        turtle.goto(-225,g )
        turtle.pendown()
        turtle.write('BMR 数值为：{}'.format(isBMR(weight,height,age)), font=("Arial", 16, "normal"))
        y_or_n = turtle.textinput('Input Please', "是否退出程序（输入y/n）：")
        if  y_or_n == 'n':
            turtle.clear()#清空turtle窗口，不改变turtle状态
        else:
           pass
    except ValueError:       #值错误   qqqqq  轻轻巧巧  轻2
        turtle.penup()
        turtle.goto(-225, 20)
        turtle.pencolor('red')
        turtle.pendown()
        turtle.write("身高，体重和年龄请输入阿拉伯数字!", font=("Arial", 16, "normal"))
        y_or_n = turtle.textinput('Input Please', "是否退出程序（输入y/n）：")
        if y_or_n == 'n':
            turtle.clear()
        else:
            pass
    except NameError:      #命名错误
        turtle.penup()
        turtle.goto(-225, 40)
        turtle.pencolor('red')
        turtle.pendown()
        turtle.write('身高，体重和年龄请输入阿拉伯数字！', font=("Arial", 16, "normal"))
        y_or_n = turtle.textinput('Input Please', "是否退出程序（输入y/n）：")
        if y_or_n == 'n':
            turtle.clear()
        else:
            pass
    except TypeError:    #类型错误
        turtle.penup()
        turtle.goto(-225,60)
        turtle.pencolor('red')
        turtle.pendown()
        turtle.write('身高，体重和年龄请输入正确的数据类型！', font=("Arial", 16, "normal"))
        y_or_n = turtle.textinput('Input Please', "是否退出程序（输入y/n）：")
        if y_or_n == 'n':
            turtle.clear()
        else:
            pass
    except IndexError:    #索引错误  1111  1
        turtle.penup()
        turtle.goto(-225,80)
        turtle.pencolor('red')
        turtle.pendown()
        turtle.write('身高，体重和年龄请以空格分开或请输入完整数据！', font=("Arial", 16, "normal"))
        y_or_n = turtle.textinput('Input Please', "是否退出程序（输入y/n）：")
        if y_or_n == 'n':
            turtle.clear()
        else:
            pass